<?php
class ControllerReportAffiliateCommission extends AdminController {
	public function index() {

		$this->document->setTitle($this->_['heading_title']);

		$qf = new Query_filter();

		M('report/affiliate');

		$this->data['affiliates'] = array();

		$affiliate_total = $this->model_report_affiliate->getTotalCommission($qf);

		$results = $this->model_report_affiliate->getCommission($qf);

		foreach ($results as $result) {
			$this->data['affiliates'][] = array(
				'affiliate'  => $result['affiliate'],
				'email'      => $result['email'],
				'status'     => ($result['status'] ? $this->_['text_enabled'] : $this->_['text_disabled']),
				'commission' => $this->currency->format($result['commission'], C('config_currency')),
				'orders'     => $result['orders'],
				'total'      => $this->currency->format($result['total'], C('config_currency')),
			);
		}

		$this->data['pagination'] = $this->pagination($affiliate_total)->render();

		$this->data['filter_date_start'] = $qf->get('filter_date_start');
		$this->data['filter_date_end'] = $qf->get('filter_date_end');

		$this->display('report/affiliate_commission.tpl');
	}
}
?>